﻿using System;
using System.Collections.Generic;
using Helpers;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.Conversation;
using TaleWorlds.CampaignSystem.MapEvents;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Roster;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.Issues
{
	// Token: 0x0200030F RID: 783
	public class LandLordTheArtOfTheTradeIssueBehavior : CampaignBehaviorBase
	{
		// Token: 0x06002D55 RID: 11605 RVA: 0x000BDBC0 File Offset: 0x000BBDC0
		public override void RegisterEvents()
		{
			CampaignEvents.OnCheckForIssueEvent.AddNonSerializedListener(this, new Action<Hero>(this.OnCheckForIssue));
		}

		// Token: 0x06002D56 RID: 11606 RVA: 0x000BDBD9 File Offset: 0x000BBDD9
		public override void SyncData(IDataStore dataStore)
		{
		}

		// Token: 0x06002D57 RID: 11607 RVA: 0x000BDBDC File Offset: 0x000BBDDC
		private bool ConditionsHold(Hero issueGiver)
		{
			if (issueGiver.IsRuralNotable)
			{
				Settlement currentSettlement = issueGiver.CurrentSettlement;
				Village village = (currentSettlement != null) ? currentSettlement.Village : null;
				return village != null && village.Bound.Town.GetItemPrice(village.VillageType.PrimaryProduction, null, false) < village.VillageType.PrimaryProduction.Value;
			}
			return false;
		}

		// Token: 0x06002D58 RID: 11608 RVA: 0x000BDC3C File Offset: 0x000BBE3C
		public void OnCheckForIssue(Hero hero)
		{
			if (this.ConditionsHold(hero))
			{
				Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(new PotentialIssueData.StartIssueDelegate(this.OnSelected), typeof(LandLordTheArtOfTheTradeIssueBehavior.LandLordTheArtOfTheTradeIssue), IssueBase.IssueFrequency.VeryCommon, null));
				return;
			}
			Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(typeof(LandLordTheArtOfTheTradeIssueBehavior.LandLordTheArtOfTheTradeIssue), IssueBase.IssueFrequency.VeryCommon));
		}

		// Token: 0x06002D59 RID: 11609 RVA: 0x000BDCA0 File Offset: 0x000BBEA0
		private IssueBase OnSelected(in PotentialIssueData pid, Hero issueOwner)
		{
			return new LandLordTheArtOfTheTradeIssueBehavior.LandLordTheArtOfTheTradeIssue(issueOwner, issueOwner.CurrentSettlement.Village.VillageType.PrimaryProduction);
		}

		// Token: 0x04000D93 RID: 3475
		private const IssueBase.IssueFrequency LandLordTheArtOfTheTradeIssueFrequency = IssueBase.IssueFrequency.VeryCommon;

		// Token: 0x04000D94 RID: 3476
		private const float TargetDenarsConstant = 0.55f;

		// Token: 0x02000641 RID: 1601
		public class LandLordTheArtOfTheTradeIssue : IssueBase
		{
			// Token: 0x06004EC6 RID: 20166 RVA: 0x00168139 File Offset: 0x00166339
			internal static void AutoGeneratedStaticCollectObjectsLandLordTheArtOfTheTradeIssue(object o, List<object> collectedObjects)
			{
				((LandLordTheArtOfTheTradeIssueBehavior.LandLordTheArtOfTheTradeIssue)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x06004EC7 RID: 20167 RVA: 0x00168147 File Offset: 0x00166347
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x17001045 RID: 4165
			// (get) Token: 0x06004EC8 RID: 20168 RVA: 0x00168150 File Offset: 0x00166350
			public override IssueBase.AlternativeSolutionScaleFlag AlternativeSolutionScaleFlags
			{
				get
				{
					return IssueBase.AlternativeSolutionScaleFlag.Duration;
				}
			}

			// Token: 0x17001046 RID: 4166
			// (get) Token: 0x06004EC9 RID: 20169 RVA: 0x00168153 File Offset: 0x00166353
			private int SelectedItemObjectCount
			{
				get
				{
					return MathF.Max(1, MathF.Round((float)((int)(5000f / (float)this._selectedItemObject.Value)) * base.IssueDifficultyMultiplier));
				}
			}

			// Token: 0x17001047 RID: 4167
			// (get) Token: 0x06004ECA RID: 20170 RVA: 0x0016817B File Offset: 0x0016637B
			public override int AlternativeSolutionBaseNeededMenCount
			{
				get
				{
					return 2 + MathF.Ceiling(4f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x17001048 RID: 4168
			// (get) Token: 0x06004ECB RID: 20171 RVA: 0x00168190 File Offset: 0x00166390
			protected override int AlternativeSolutionBaseDurationInDaysInternal
			{
				get
				{
					return 3 + MathF.Ceiling(5f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x17001049 RID: 4169
			// (get) Token: 0x06004ECC RID: 20172 RVA: 0x001681A5 File Offset: 0x001663A5
			protected override int RewardGold
			{
				get
				{
					return (int)((float)(this._selectedItemObject.Value * this.SelectedItemObjectCount) * this.RewardGoldDeterministicRandomContribution);
				}
			}

			// Token: 0x1700104A RID: 4170
			// (get) Token: 0x06004ECD RID: 20173 RVA: 0x001681C2 File Offset: 0x001663C2
			private float RewardGoldDeterministicRandomContribution
			{
				get
				{
					return base.IssueOwner.RandomFloatWithSeed((uint)this.IssueCreationTime.ElapsedDaysUntilNow, 0.2f, 0.5f);
				}
			}

			// Token: 0x1700104B RID: 4171
			// (get) Token: 0x06004ECE RID: 20174 RVA: 0x001681E8 File Offset: 0x001663E8
			public override TextObject IssueBriefByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=AKdDSZoM}Yes. It's a good problem to have, though. As you know, I deal in {.%}{SELECTED_ITEM}{.%}. Production this year has been very good, and we can no longer make a profit on the local market. I cannot however, put together a caravan to sell it elsewhere. So, I propose a very simple deal.[if:convo_innocent_smile][ib:confident]", null);
					if (this._selectedItemObject.HasHorseComponent || this._selectedItemObject.IsAnimal)
					{
						textObject = new TextObject("{=llVFTH6n}Yes. It's a good problem to have, though. As you may know, I deal in {PLURAL(SELECTED_ITEM)}. Our herds have increased this year, and we can no longer make a profit on the local market. I cannot however organize a drive to a new market. So, I propose a very simple deal.[if:convo_innocent_smile][ib:confident]", null);
					}
					textObject.SetTextVariable("SELECTED_ITEM", this._selectedItemObject.Name);
					return textObject;
				}
			}

			// Token: 0x1700104C RID: 4172
			// (get) Token: 0x06004ECF RID: 20175 RVA: 0x0016823F File Offset: 0x0016643F
			public override TextObject IssueAcceptByPlayer
			{
				get
				{
					return new TextObject("{=8jyUn6mb}You sell me the goods at a discount?", null);
				}
			}

			// Token: 0x1700104D RID: 4173
			// (get) Token: 0x06004ED0 RID: 20176 RVA: 0x0016824C File Offset: 0x0016644C
			public override TextObject IssueQuestSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=rWnvnufw}That could work, if you have the money. But if you don't, I'm willing to take a chance on you. I reckon for {SELECTED_ITEM_COUNT} {.%}{?SELECTED_ITEM_COUNT > 1}{PLURAL(SELECTED_ITEM)}{?}{SELECTED_ITEM}{\\?}{.%} you can probably find a market nearby where buyers will pay you a total of {TOTAL_GOLD}{GOLD_ICON}. Here's my offer. I loan you the product. You sell it at whatever price you like, and bring me back {TOTAL_GOLD}{GOLD_ICON} denars. I have little doubt you could find a market where you could get a better price than this, and make a profit.[if:convo_innocent_smile][ib:confident]", null);
					if (this._selectedItemObject.HasHorseComponent || this._selectedItemObject.IsAnimal)
					{
						textObject = new TextObject("{=b19Hlp7h}That could work, if you have the money. But if you don't, I'm willing to take a chance on you. I reckon for {SELECTED_ITEM_COUNT} {?SELECTED_ITEM_COUNT > 1}{PLURAL(SELECTED_ITEM)}{?}{SELECTED_ITEM}{\\?} you can probably find a market nearby where buyers will pay you a total of {TOTAL_GOLD}{GOLD_ICON}. Here's my offer. I loan you the livestock. You sell at whatever price you like, and bring me back {TOTAL_GOLD}{GOLD_ICON} denars. I have little doubt you could find a market where you could get a better price than this, and make a profit.[if:convo_innocent_smile][ib:confident]", null);
					}
					textObject.SetTextVariable("TOTAL_GOLD", (int)((float)(this._selectedItemObject.Value * this.SelectedItemObjectCount) * 0.55f));
					textObject.SetTextVariable("SELECTED_ITEM_COUNT", this.SelectedItemObjectCount);
					textObject.SetTextVariable("SELECTED_ITEM", this._selectedItemObject.Name);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x1700104E RID: 4174
			// (get) Token: 0x06004ED1 RID: 20177 RVA: 0x001682EC File Offset: 0x001664EC
			public override TextObject IssuePlayerResponseAfterAlternativeExplanation
			{
				get
				{
					return new TextObject("{=w1rVTUIs}This seems like a simple errand. Would your offer still stand if I get someone else to do it for me?", null);
				}
			}

			// Token: 0x1700104F RID: 4175
			// (get) Token: 0x06004ED2 RID: 20178 RVA: 0x001682F9 File Offset: 0x001664F9
			public override TextObject IssueAlternativeSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=PE97ZWvX}Not just anybody. If you have a companion that has your complete trust, then I'll agree... Just make sure he is well guarded. Goods attract bandits, as I'm sure you know. I suppose {ALTERNATIVE_TROOP_AMOUNT} well-armed men would be enough.[if:convo_innocent_smile][ib:confident]", null);
					textObject.SetTextVariable("ALTERNATIVE_TROOP_AMOUNT", base.GetTotalAlternativeSolutionNeededMenCount());
					return textObject;
				}
			}

			// Token: 0x17001050 RID: 4176
			// (get) Token: 0x06004ED3 RID: 20179 RVA: 0x00168318 File Offset: 0x00166518
			public override TextObject IssueQuestSolutionAcceptByPlayer
			{
				get
				{
					TextObject textObject = new TextObject("{=aB0TT6Ur}Fear not. I will find the right market for your {.%}{SELECTED_ITEM}{.%} myself.", null);
					if (this._selectedItemObject.HasHorseComponent || this._selectedItemObject.IsAnimal)
					{
						textObject = new TextObject("{=cBO49V5b}Fear not. I will find the right market for your {PLURAL(SELECTED_ITEM)} myself.", null);
					}
					textObject.SetTextVariable("SELECTED_ITEM", this._selectedItemObject.Name);
					return textObject;
				}
			}

			// Token: 0x17001051 RID: 4177
			// (get) Token: 0x06004ED4 RID: 20180 RVA: 0x0016836F File Offset: 0x0016656F
			public override TextObject IssueAlternativeSolutionAcceptByPlayer
			{
				get
				{
					TextObject textObject = new TextObject("{=IFasMslv}I will assign a companion with {TROOP_COUNT} good men for {RETURN_DAYS} days.", null);
					textObject.SetTextVariable("TROOP_COUNT", base.GetTotalAlternativeSolutionNeededMenCount());
					textObject.SetTextVariable("RETURN_DAYS", base.GetTotalAlternativeSolutionDurationInDays());
					return textObject;
				}
			}

			// Token: 0x17001052 RID: 4178
			// (get) Token: 0x06004ED5 RID: 20181 RVA: 0x001683A0 File Offset: 0x001665A0
			public override TextObject IssueDiscussAlternativeSolution
			{
				get
				{
					return new TextObject("{=dLywF1Uz}I have heard your companion has started to sell the goods. This was a good deal, {?PLAYER.GENDER}ma'am{?}sir{\\?}.[if:convo_relaxed_happy][ib:confident]", null);
				}
			}

			// Token: 0x17001053 RID: 4179
			// (get) Token: 0x06004ED6 RID: 20182 RVA: 0x001683AD File Offset: 0x001665AD
			public override TextObject IssueAlternativeSolutionResponseByIssueGiver
			{
				get
				{
					return new TextObject("{=aUXAh8cE}Very well, {PLAYER.NAME}. If you're willing to vouch for your companion, I'm sure this will work.[if:convo_innocent_smile][ib:confident]", null);
				}
			}

			// Token: 0x17001054 RID: 4180
			// (get) Token: 0x06004ED7 RID: 20183 RVA: 0x001683BA File Offset: 0x001665BA
			public override bool IsThereAlternativeSolution
			{
				get
				{
					return true;
				}
			}

			// Token: 0x17001055 RID: 4181
			// (get) Token: 0x06004ED8 RID: 20184 RVA: 0x001683BD File Offset: 0x001665BD
			public override bool IsThereLordSolution
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17001056 RID: 4182
			// (get) Token: 0x06004ED9 RID: 20185 RVA: 0x001683C0 File Offset: 0x001665C0
			protected override TextObject AlternativeSolutionStartLog
			{
				get
				{
					TextObject textObject = new TextObject("{=BK9ww4NU}{QUEST_GIVER.LINK} asked you to sell {?QUEST_GIVER.GENDER}her{?}his{\\?} goods for at least {UNIT_PRICE}{GOLD_ICON} per {UNIT_NAME} and return to {?QUEST_GIVER.GENDER}her{?}him{\\?}. {?QUEST_GIVER.GENDER}She{?}He{\\?} told you that any profit that the deal would make above this price is yours to keep. You asked {COMPANION.LINK} to take {TROOP_COUNT} of your best men to go and take care of it. They should report back to you in {RETURN_DAYS} days.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.IssueOwner.CharacterObject, textObject, true);
					StringHelpers.SetCharacterProperties("COMPANION", base.AlternativeSolutionHero.CharacterObject, textObject, false);
					textObject.SetTextVariable("UNIT_NAME", "{=g72xNv75}load");
					if (this._selectedItemObject.HasHorseComponent || this._selectedItemObject.IsAnimal)
					{
						textObject.SetTextVariable("UNIT_NAME", "{=T9Tgi9is}animal");
					}
					textObject.SetTextVariable("UNIT_PRICE", this._selectedItemObject.Value);
					textObject.SetTextVariable("RETURN_DAYS", base.GetTotalAlternativeSolutionDurationInDays());
					textObject.SetTextVariable("TROOP_COUNT", base.GetTotalAlternativeSolutionNeededMenCount());
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x17001057 RID: 4183
			// (get) Token: 0x06004EDA RID: 20186 RVA: 0x00168494 File Offset: 0x00166694
			public override TextObject IssueAlternativeSolutionSuccessLog
			{
				get
				{
					TextObject textObject = new TextObject("{=BDAmZkJF}You received a message from {ISSUE_GIVER.LINK}. 'It was a pleasure doing business with you and your folks.'", null);
					StringHelpers.SetCharacterProperties("ISSUE_GIVER", base.IssueOwner.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001058 RID: 4184
			// (get) Token: 0x06004EDB RID: 20187 RVA: 0x001684C6 File Offset: 0x001666C6
			public override TextObject Title
			{
				get
				{
					return new TextObject("{=96m29Eb7}The Art of The Trade", null);
				}
			}

			// Token: 0x17001059 RID: 4185
			// (get) Token: 0x06004EDC RID: 20188 RVA: 0x001684D3 File Offset: 0x001666D3
			public override TextObject Description
			{
				get
				{
					TextObject result = new TextObject("{=BZwKEIm5}{ISSUE_GIVER.LINK} wants you to sell {?ISSUE_GIVER.GENDER}her{?}his{\\?} goods for a price above the global average.", null);
					StringHelpers.SetCharacterProperties("ISSUE_GIVER", base.IssueOwner.CharacterObject, null, false);
					return result;
				}
			}

			// Token: 0x06004EDD RID: 20189 RVA: 0x001684F8 File Offset: 0x001666F8
			public LandLordTheArtOfTheTradeIssue(Hero issueOwner, ItemObject villageProduction) : base(issueOwner, CampaignTime.DaysFromNow(30f))
			{
				this._selectedItemObject = villageProduction;
			}

			// Token: 0x06004EDE RID: 20190 RVA: 0x00168512 File Offset: 0x00166712
			protected override float GetIssueEffectAmountInternal(IssueEffect issueEffect)
			{
				if (issueEffect == DefaultIssueEffects.VillageHearth)
				{
					return -0.1f;
				}
				if (issueEffect == DefaultIssueEffects.IssueOwnerPower)
				{
					return -0.1f;
				}
				return 0f;
			}

			// Token: 0x06004EDF RID: 20191 RVA: 0x00168535 File Offset: 0x00166735
			public override ValueTuple<SkillObject, int> GetAlternativeSolutionSkill(Hero hero)
			{
				return new ValueTuple<SkillObject, int>((hero.GetSkillValue(DefaultSkills.Trade) >= hero.GetSkillValue(DefaultSkills.Riding)) ? DefaultSkills.Trade : DefaultSkills.Riding, 120);
			}

			// Token: 0x06004EE0 RID: 20192 RVA: 0x00168564 File Offset: 0x00166764
			public override bool DoTroopsSatisfyAlternativeSolution(TroopRoster troopRoster, out TextObject explanation)
			{
				int totalAlternativeSolutionNeededMenCount = base.GetTotalAlternativeSolutionNeededMenCount();
				if (this.GetNumberOfTier2Troops(troopRoster) < totalAlternativeSolutionNeededMenCount)
				{
					explanation = new TextObject("{=rJIY7OiR}You have to send {NEEDED_TROOP_COUNT} troops with at least tier 2 to this quest.", null);
					explanation.SetTextVariable("NEEDED_TROOP_COUNT", totalAlternativeSolutionNeededMenCount);
					return false;
				}
				explanation = TextObject.Empty;
				return true;
			}

			// Token: 0x06004EE1 RID: 20193 RVA: 0x001685A8 File Offset: 0x001667A8
			private int GetNumberOfTier2Troops(TroopRoster troopRoster)
			{
				int num = 0;
				foreach (TroopRosterElement troopRosterElement in troopRoster.GetTroopRoster())
				{
					if (troopRosterElement.Character.Tier >= 2)
					{
						num += troopRoster.GetTroopCount(troopRosterElement.Character) - troopRoster.GetElementWoundedNumber(troopRoster.FindIndexOfTroop(troopRosterElement.Character));
					}
				}
				return num;
			}

			// Token: 0x06004EE2 RID: 20194 RVA: 0x00168628 File Offset: 0x00166828
			public override IssueBase.IssueFrequency GetFrequency()
			{
				return IssueBase.IssueFrequency.VeryCommon;
			}

			// Token: 0x06004EE3 RID: 20195 RVA: 0x0016862C File Offset: 0x0016682C
			public override bool IssueStayAliveConditions()
			{
				return !base.IssueOwner.CurrentSettlement.IsRaided && !base.IssueOwner.CurrentSettlement.IsUnderRaid && (float)base.IssueOwner.CurrentSettlement.Village.Bound.Town.GetItemPrice(base.IssueOwner.CurrentSettlement.Village.VillageType.PrimaryProduction, null, false) < (float)base.IssueOwner.CurrentSettlement.Village.VillageType.PrimaryProduction.Value * 1.3f;
			}

			// Token: 0x06004EE4 RID: 20196 RVA: 0x001686C4 File Offset: 0x001668C4
			protected override bool CanPlayerTakeQuestConditions(Hero issueGiver, out IssueBase.PreconditionFlags flags, out Hero relationHero, out SkillObject skill)
			{
				flags = IssueBase.PreconditionFlags.None;
				relationHero = null;
				skill = null;
				if (issueGiver.GetRelationWithPlayer() < -10f)
				{
					flags |= IssueBase.PreconditionFlags.Relation;
					relationHero = issueGiver;
				}
				if (FactionManager.IsAtWarAgainstFaction(issueGiver.MapFaction, Hero.MainHero.MapFaction))
				{
					flags |= IssueBase.PreconditionFlags.AtWar;
				}
				return flags == IssueBase.PreconditionFlags.None;
			}

			// Token: 0x06004EE5 RID: 20197 RVA: 0x00168714 File Offset: 0x00166914
			protected override void OnGameLoad()
			{
				this._selectedItemObject = base.IssueOwner.CurrentSettlement.Village.VillageType.PrimaryProduction;
			}

			// Token: 0x06004EE6 RID: 20198 RVA: 0x00168736 File Offset: 0x00166936
			protected override void HourlyTick()
			{
			}

			// Token: 0x06004EE7 RID: 20199 RVA: 0x00168738 File Offset: 0x00166938
			protected override QuestBase GenerateIssueQuest(string questId)
			{
				return new LandLordTheArtOfTheTradeIssueBehavior.LandLordTheArtOfTheTradeIssueQuest(questId, base.IssueOwner, CampaignTime.DaysFromNow(30f), this._selectedItemObject, this.SelectedItemObjectCount);
			}

			// Token: 0x06004EE8 RID: 20200 RVA: 0x0016875C File Offset: 0x0016695C
			protected override void CompleteIssueWithTimedOutConsequences()
			{
			}

			// Token: 0x1700105A RID: 4186
			// (get) Token: 0x06004EE9 RID: 20201 RVA: 0x0016875E File Offset: 0x0016695E
			protected override int CompanionSkillRewardXP
			{
				get
				{
					return (int)(900f + 800f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x06004EEA RID: 20202 RVA: 0x00168773 File Offset: 0x00166973
			protected override void AlternativeSolutionEndWithSuccessConsequence()
			{
				GainRenownAction.Apply(Hero.MainHero, 1f, false);
				this.RelationshipChangeWithIssueOwner = 10;
			}

			// Token: 0x04001A34 RID: 6708
			private const int IssueAndQuestDuration = 30;

			// Token: 0x04001A35 RID: 6709
			private const int CompanionRequiredSkillLevel = 120;

			// Token: 0x04001A36 RID: 6710
			private ItemObject _selectedItemObject;
		}

		// Token: 0x02000642 RID: 1602
		public class LandLordTheArtOfTheTradeIssueQuest : QuestBase
		{
			// Token: 0x06004EEB RID: 20203 RVA: 0x0016878D File Offset: 0x0016698D
			internal static void AutoGeneratedStaticCollectObjectsLandLordTheArtOfTheTradeIssueQuest(object o, List<object> collectedObjects)
			{
				((LandLordTheArtOfTheTradeIssueBehavior.LandLordTheArtOfTheTradeIssueQuest)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x06004EEC RID: 20204 RVA: 0x0016879B File Offset: 0x0016699B
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._selectedItemObject);
				collectedObjects.Add(this._soldItemAmountLog);
				collectedObjects.Add(this._gatheredDenarsLog);
			}

			// Token: 0x06004EED RID: 20205 RVA: 0x001687C8 File Offset: 0x001669C8
			internal static object AutoGeneratedGetMemberValue_selectedItemObject(object o)
			{
				return ((LandLordTheArtOfTheTradeIssueBehavior.LandLordTheArtOfTheTradeIssueQuest)o)._selectedItemObject;
			}

			// Token: 0x06004EEE RID: 20206 RVA: 0x001687D5 File Offset: 0x001669D5
			internal static object AutoGeneratedGetMemberValue_selectedItemObjectCount(object o)
			{
				return ((LandLordTheArtOfTheTradeIssueBehavior.LandLordTheArtOfTheTradeIssueQuest)o)._selectedItemObjectCount;
			}

			// Token: 0x06004EEF RID: 20207 RVA: 0x001687E7 File Offset: 0x001669E7
			internal static object AutoGeneratedGetMemberValue_soldCount(object o)
			{
				return ((LandLordTheArtOfTheTradeIssueBehavior.LandLordTheArtOfTheTradeIssueQuest)o)._soldCount;
			}

			// Token: 0x06004EF0 RID: 20208 RVA: 0x001687F9 File Offset: 0x001669F9
			internal static object AutoGeneratedGetMemberValue_gatheredDenars(object o)
			{
				return ((LandLordTheArtOfTheTradeIssueBehavior.LandLordTheArtOfTheTradeIssueQuest)o)._gatheredDenars;
			}

			// Token: 0x06004EF1 RID: 20209 RVA: 0x0016880B File Offset: 0x00166A0B
			internal static object AutoGeneratedGetMemberValue_daysPassed(object o)
			{
				return ((LandLordTheArtOfTheTradeIssueBehavior.LandLordTheArtOfTheTradeIssueQuest)o)._daysPassed;
			}

			// Token: 0x06004EF2 RID: 20210 RVA: 0x0016881D File Offset: 0x00166A1D
			internal static object AutoGeneratedGetMemberValue_underSoldLogAdded(object o)
			{
				return ((LandLordTheArtOfTheTradeIssueBehavior.LandLordTheArtOfTheTradeIssueQuest)o)._underSoldLogAdded;
			}

			// Token: 0x06004EF3 RID: 20211 RVA: 0x0016882F File Offset: 0x00166A2F
			internal static object AutoGeneratedGetMemberValue_soldItemAmountLog(object o)
			{
				return ((LandLordTheArtOfTheTradeIssueBehavior.LandLordTheArtOfTheTradeIssueQuest)o)._soldItemAmountLog;
			}

			// Token: 0x06004EF4 RID: 20212 RVA: 0x0016883C File Offset: 0x00166A3C
			internal static object AutoGeneratedGetMemberValue_gatheredDenarsLog(object o)
			{
				return ((LandLordTheArtOfTheTradeIssueBehavior.LandLordTheArtOfTheTradeIssueQuest)o)._gatheredDenarsLog;
			}

			// Token: 0x1700105B RID: 4187
			// (get) Token: 0x06004EF5 RID: 20213 RVA: 0x00168849 File Offset: 0x00166A49
			public override TextObject Title
			{
				get
				{
					return new TextObject("{=96m29Eb7}The Art of The Trade", null);
				}
			}

			// Token: 0x1700105C RID: 4188
			// (get) Token: 0x06004EF6 RID: 20214 RVA: 0x00168856 File Offset: 0x00166A56
			public override bool IsRemainingTimeHidden
			{
				get
				{
					return false;
				}
			}

			// Token: 0x1700105D RID: 4189
			// (get) Token: 0x06004EF7 RID: 20215 RVA: 0x0016885C File Offset: 0x00166A5C
			private bool QuestCanBeFinalized
			{
				get
				{
					return Hero.OneToOneConversationHero != null && Hero.OneToOneConversationHero == base.QuestGiver && (this.ItemCountLeftToSell <= 0 || this._targetDenarsToAchieve <= this._gatheredDenars || (this._daysPassed >= 1 && this.CheckIfPlayerLostItem()));
				}
			}

			// Token: 0x1700105E RID: 4190
			// (get) Token: 0x06004EF8 RID: 20216 RVA: 0x001688A9 File Offset: 0x00166AA9
			private int ItemCountLeftToSell
			{
				get
				{
					return this._selectedItemObjectCount - this._soldCount;
				}
			}

			// Token: 0x1700105F RID: 4191
			// (get) Token: 0x06004EF9 RID: 20217 RVA: 0x001688B8 File Offset: 0x00166AB8
			private int RemainingDenars
			{
				get
				{
					return this._targetDenarsToAchieve - this._gatheredDenars;
				}
			}

			// Token: 0x17001060 RID: 4192
			// (get) Token: 0x06004EFA RID: 20218 RVA: 0x001688C8 File Offset: 0x00166AC8
			private TextObject QuestStartedLogText1
			{
				get
				{
					TextObject textObject = new TextObject("{=2bcNCnI3}{QUEST_GIVER.LINK} asked you to sell {?QUEST_GIVER.GENDER}her{?}his{\\?} goods for at least {UNIT_PRICE}{GOLD_ICON} per load and return to {?QUEST_GIVER.GENDER}her{?}him{\\?}. {?QUEST_GIVER.GENDER}She{?}He{\\?} told you that any profit would make above this price is yours to keep.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, true);
					textObject.SetTextVariable("UNIT_PRICE", this._targetDenarsToAchieve / this._selectedItemObjectCount);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x17001061 RID: 4193
			// (get) Token: 0x06004EFB RID: 20219 RVA: 0x00168924 File Offset: 0x00166B24
			private TextObject QuestStartedLogText2
			{
				get
				{
					TextObject textObject = new TextObject("{=jI251oj9}{?QUEST_GIVER.GENDER}She{?}He{\\?} noted that {?QUEST_GIVER.GENDER}she{?}he{\\?} has {SELECTED_ITEM_COUNT} {.%}{?SELECTED_ITEM_COUNT > 1}{PLURAL(SELECTED_ITEM)}{?}{SELECTED_ITEM}{\\?}{.%}. {?QUEST_GIVER.GENDER}She{?}He{\\?} is expecting to earn {TOTAL_GOLD}{GOLD_ICON} denars from that.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("SELECTED_ITEM_COUNT", this._selectedItemObjectCount);
					textObject.SetTextVariable("SELECTED_ITEM", this._selectedItemObject.Name);
					textObject.SetTextVariable("TOTAL_GOLD", this._targetDenarsToAchieve);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x17001062 RID: 4194
			// (get) Token: 0x06004EFC RID: 20220 RVA: 0x001689A4 File Offset: 0x00166BA4
			private TextObject QuestStartedLogText3
			{
				get
				{
					TextObject textObject = new TextObject("{=tf04Piaj}You told {?QUEST_GIVER.GENDER}her{?}him{\\?} that you will sell the goods personally.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001063 RID: 4195
			// (get) Token: 0x06004EFD RID: 20221 RVA: 0x001689D6 File Offset: 0x00166BD6
			private TextObject QuestSuccessLogText
			{
				get
				{
					return new TextObject("{=EsNDadiR}You have completed your end of your bargain and made some denars simply by using your smarts.", null);
				}
			}

			// Token: 0x17001064 RID: 4196
			// (get) Token: 0x06004EFE RID: 20222 RVA: 0x001689E4 File Offset: 0x00166BE4
			private TextObject QuestReadyToBeFinishedLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=2GMOnUIM}{QUEST_GIVER.LINK} expects your return to have {?QUEST_GIVER.GENDER}her{?}his{\\?} share of the deal.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001065 RID: 4197
			// (get) Token: 0x06004EFF RID: 20223 RVA: 0x00168A28 File Offset: 0x00166C28
			private TextObject QuestReadyToBeFinishedUnderSoldLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=IfPnl0B6}You have lost some of the wares you were supposed to be selling. You can speak with {QUEST_GIVER.LINK} to pay for a compensation.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001066 RID: 4198
			// (get) Token: 0x06004F00 RID: 20224 RVA: 0x00168A5C File Offset: 0x00166C5C
			private TextObject QuestSuccessWithPayingGatheredDenarsLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=4bDHBIr1}You have completed your end of the bargain. {QUEST_GIVER.LINK} now considers you as a trustworthy {?PLAYER.GENDER}tradeswoman{?}tradesman{\\?}.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001067 RID: 4199
			// (get) Token: 0x06004F01 RID: 20225 RVA: 0x00168AA0 File Offset: 0x00166CA0
			private TextObject QuestSuccessPlayerBoughtItemsLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=rYt43AWk}{QUEST_GIVER.LINK} accepted your offer to buy the products from an average price. You can now sell those for profits without any obligations to {?QUEST_GIVER.GENDER}her{?}him{\\?}.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17001068 RID: 4200
			// (get) Token: 0x06004F02 RID: 20226 RVA: 0x00168AD4 File Offset: 0x00166CD4
			private TextObject QuestFailedPlayerBrokeTheAgreementLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=1q2dxlol}You have failed to pay {TOTAL_DENAR}{GOLD_ICON} denars to {QUEST_GIVER.LINK}. {QUEST_GIVER_VILLAGE} and its locals are aware of your misdemeanor.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("QUEST_GIVER_VILLAGE", base.QuestGiver.CurrentSettlement.EncyclopediaLinkWithName);
					textObject.SetTextVariable("TOTAL_DENAR", this._targetDenarsToAchieve);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x17001069 RID: 4201
			// (get) Token: 0x06004F03 RID: 20227 RVA: 0x00168B48 File Offset: 0x00166D48
			private TextObject QuestCanceledWarDeclaredLog
			{
				get
				{
					TextObject textObject = new TextObject("{=vW6kBki9}Your clan is now at war with {QUEST_GIVER.LINK}'s realm. Your agreement with {QUEST_GIVER.LINK} is canceled.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x1700106A RID: 4202
			// (get) Token: 0x06004F04 RID: 20228 RVA: 0x00168B7C File Offset: 0x00166D7C
			private TextObject PlayerDeclaredWarQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=bqeWVVEE}Your actions have started a war with {QUEST_GIVER.LINK}'s faction. {?QUEST_GIVER.GENDER}She{?}He{\\?} cancels your agreement and the quest is a failure.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x1700106B RID: 4203
			// (get) Token: 0x06004F05 RID: 20229 RVA: 0x00168BB0 File Offset: 0x00166DB0
			private TextObject QuestGiverVillageRaided
			{
				get
				{
					TextObject textObject = new TextObject("{=w0FD9U98}{QUEST_GIVER.LINK}'s village is raided. Your agreement with {?QUEST_GIVER.GENDER}her{?}him{\\?} is moot.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("QUEST_SETTLEMENT", base.QuestGiver.CurrentSettlement.EncyclopediaLinkWithName);
					return textObject;
				}
			}

			// Token: 0x1700106C RID: 4204
			// (get) Token: 0x06004F06 RID: 20230 RVA: 0x00168C00 File Offset: 0x00166E00
			private TextObject QuestFailedWithTimeOutLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=PQt8lfTX}You have failed to return to the {QUEST_GIVER.LINK} in time. {QUEST_GIVER_VILLAGE} and its locals are aware of your misdemeanor.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("QUEST_GIVER_VILLAGE", base.QuestGiver.CurrentSettlement.EncyclopediaLinkWithName);
					return textObject;
				}
			}

			// Token: 0x06004F07 RID: 20231 RVA: 0x00168C50 File Offset: 0x00166E50
			public LandLordTheArtOfTheTradeIssueQuest(string questId, Hero giverHero, CampaignTime duration, ItemObject selectedItemObject, int selectedItemObjectCount) : base(questId, giverHero, duration, 0)
			{
				this._selectedItemObject = selectedItemObject;
				this._selectedItemObjectCount = selectedItemObjectCount;
				this._targetDenarsToAchieve = (int)((float)(selectedItemObject.Value * selectedItemObjectCount) * 0.55f);
				this._daysPassed = 0;
				this.SetDialogs();
				base.InitializeQuestOnCreation();
			}

			// Token: 0x06004F08 RID: 20232 RVA: 0x00168CAC File Offset: 0x00166EAC
			protected override void SetDialogs()
			{
				TextObject textObject = new TextObject("{=3Sk0BQ4n}I will buy the products from you for {TOTAL_GOLD}{GOLD_ICON}. This way we both will get what we desire.", null);
				if (this._selectedItemObject.IsAnimal || this._selectedItemObject.HasHorseComponent)
				{
					textObject = new TextObject("{=7nBOWsg2}I will buy the livestock from you for {TOTAL_GOLD}{GOLD_ICON}. This way we both will get what we desire.", null);
				}
				textObject.SetTextVariable("TOTAL_GOLD", this._targetDenarsToAchieve);
				textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
				TextObject textObject2 = new TextObject("{=iYtzlRSN}I would rather be your middleman on this matter. I need to keep my money. You can have your men load up the {.%}{SELECTED_ITEM}{.%} already.", null);
				if (this._selectedItemObject.IsAnimal || this._selectedItemObject.HasHorseComponent)
				{
					textObject2 = new TextObject("{=exmSGWUb}I would rather be your middleman on this matter. I need to keep my money. You can have your men get the herd ready.", null);
				}
				textObject2.SetTextVariable("SELECTED_ITEM", this._selectedItemObject.Name);
				TextObject textObject3 = new TextObject("{=9d6WxRrj}Do you want to buy the goods yourself? Or will I retain ownership, and you just keep the extra profits? I am expecting to earn {TOTAL_DENARS}{GOLD_ICON} for {SELECTED_COUNT} loads of produce. If would like to buy it right away you can simply sell it yourself or do whatever you wish with it.", null);
				if (this._selectedItemObject.IsAnimal || this._selectedItemObject.HasHorseComponent)
				{
					textObject3 = new TextObject("{=GihVcxIB}Do you want to buy the livestock yourself? Or will I retain ownership, and you just keep the extra profits? I am expecting to earn {TOTAL_DENARS}{GOLD_ICON} in total. If would like to buy the livestock right away you can simply sell it yourself or do whatever you wish with it.", null);
				}
				textObject3.SetTextVariable("TOTAL_DENARS", this._targetDenarsToAchieve);
				textObject3.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
				textObject3.SetTextVariable("SELECTED_COUNT", this._selectedItemObjectCount);
				this.OfferDialogFlow = DialogFlow.CreateDialogFlow("issue_classic_quest_start", 100).NpcLine(new TextObject("{=NaoYCmC6}Good. Needless to say, by not taking any money up front, I am trusting in your honesty in your ability to protect those goods. But I am sure that trust will not be misplaced.[if:convo_innocent_smile][ib:closed]", null), null, null).Condition(() => Hero.OneToOneConversationHero == this.QuestGiver).NpcLine(textObject3, null, null).BeginPlayerOptions().PlayerOption(textObject, null).ClickableCondition(new ConversationSentence.OnClickableConditionDelegate(this.PlayerBuyClickableOptionCondition)).NpcLine(new TextObject("{=LmTii9E2}It was a pleasure doing business with you. If only everyone was as honest as you.[if:convo_happy][ib:confident3]", null), null, null).Consequence(delegate
				{
					this.StartQuest();
					this.QuestFinishedPlayerBoughtTheGoods();
				}).CloseDialog().PlayerOption(textObject2, null).Consequence(new ConversationSentence.OnConsequenceDelegate(this.QuestAcceptedConsequences)).CloseDialog().EndPlayerOptions().CloseDialog();
				TextObject playerMainOptionOneWithGold = new TextObject("{=1zdkXAwL}The market isn't what we expected. I am afraid I only made {GATHERED_DENARS}{GOLD_ICON} of the {TOTAL_DENARS}{GOLD_ICON} that we agreed upon.", null);
				playerMainOptionOneWithGold.SetTextVariable("GATHERED_DENARS", this._gatheredDenars);
				playerMainOptionOneWithGold.SetTextVariable("TOTAL_DENARS", this._targetDenarsToAchieve);
				playerMainOptionOneWithGold.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
				TextObject playerMainOptionOneNoGold = new TextObject("{=52lNazA1}I'm afraid that things came up. I was not able to make the sale.", null);
				TextObject text = new TextObject("{=!}{PLAYER_OPTION}", null);
				TextObject textObject4 = new TextObject("{=THD3C7xc}I have. Here is the {TOTAL_DENARS}{GOLD_ICON} denars just as we agreed.[ib:hip2]", null);
				textObject4.SetTextVariable("TOTAL_DENARS", this._targetDenarsToAchieve);
				textObject4.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
				TextObject textObject5 = new TextObject("{=z47GjqTZ}Yes, of course. This is the {TOTAL_DENARS}{GOLD_ICON} denars that I owe you.[ib:hip2]", null);
				textObject5.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
				textObject5.SetTextVariable("TOTAL_DENARS", this._targetDenarsToAchieve);
				TextObject playerFailOptionWithGold = new TextObject("{=dtzKfkrh}We never agreed on this. I am not paying you any more than {GATHERED_DENARS}{GOLD_ICON}, and you cannot force me.", null);
				playerFailOptionWithGold.SetTextVariable("GATHERED_DENARS", this._gatheredDenars);
				TextObject playerFailOptionNoGold = new TextObject("{=aFDiKxhr}Our deal involved you getting your cut from the sales I made. No sale means no cut. I'm sure you understand.[ib:warrior2]", null);
				TextObject text2 = new TextObject("{=!}{PLAYER_FAIL_OPTION}", null);
				TextObject textObject6 = new TextObject("{=41wb8QaV}I know I can not force you to pay you what you owe me. But I think you will find that a good name is worth more than a few loads of {SELECTED_ITEM}...", null);
				textObject6.SetTextVariable("SELECTED_ITEM", this._selectedItemObject.Name);
				if (this._selectedItemObject.IsAnimal || this._selectedItemObject.HasHorseComponent)
				{
					textObject6 = new TextObject("{=pcrdOlE8}I know I can not force you to pay you what you owe me. But I think you will find that a good name is worth more than a bit of livestock...", null);
				}
				TextObject textObject7 = new TextObject("{=OIwtLKN3}I am a {?PLAYER.GENDER}woman{?}man{\\?} of my word. I will raise some money to pay you. Wait for my return {QUEST_GIVER.LINK}.", null);
				StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, textObject7, false);
				StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject7, false);
				TextObject textObject8 = new TextObject("{=bPPXiybO}I just happened to be around. Have no fear {QUEST_GIVER.NAME}, your goods are fine.", null);
				StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject8, false);
				TextObject npcText = new TextObject("{=ekSg8okD}I will be better once you return with the denars you owe me {PLAYER.NAME}.[ib:aggressive2]", null);
				StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, textObject8, false);
				TextObject textObject9 = new TextObject("{=bbsN6hOo}Have you already sold that {SELECTED_ITEM}? If so, that seems awfully quick.", null);
				textObject9.SetTextVariable("SELECTED_ITEM", this._selectedItemObject.Name);
				this.DiscussDialogFlow = DialogFlow.CreateDialogFlow("quest_discuss", 100).BeginNpcOptions().NpcOption(textObject9, () => Hero.OneToOneConversationHero != null && Hero.OneToOneConversationHero == this.QuestGiver && !this.QuestCanBeFinalized, null, null).BeginPlayerOptions().PlayerOption(new TextObject("{=gVad94Br}I was just checking in with you.", null), null).Condition(() => !this.QuestCanBeFinalized).NpcLine(npcText, null, null).CloseDialog().PlayerOption(textObject8, null).Condition(() => !this.QuestCanBeFinalized).NpcLine(npcText, null, null).CloseDialog().EndPlayerOptions().NpcOption(new TextObject("{=1q3FKY1s}Have you made your trip yet? I presume you were able to make a sale?", null), () => Hero.OneToOneConversationHero != null && Hero.OneToOneConversationHero == this.QuestGiver && this.QuestCanBeFinalized, null, null).BeginPlayerOptions().PlayerOption(text, null).Condition(delegate
				{
					if (this._gatheredDenars > 0)
					{
						playerMainOptionOneWithGold.SetTextVariable("GATHERED_DENARS", this._gatheredDenars);
						Campaign.Current.ConversationManager.GetCurrentDialogLine().SetTextVariable("PLAYER_OPTION", playerMainOptionOneWithGold);
					}
					else
					{
						Campaign.Current.ConversationManager.GetCurrentDialogLine().SetTextVariable("PLAYER_OPTION", playerMainOptionOneNoGold);
					}
					return this.QuestCanBeFinalized && this._productsUndersold;
				}).NpcLine(new TextObject("{=QlYUE00L}Well. We did have an agreement. I do expect you to pay the full amount.", null), null, null).BeginPlayerOptions().PlayerOption(textObject5, null).ClickableCondition(new ConversationSentence.OnClickableConditionDelegate(this.PlayerPayAgreedDenarsClickableCondition)).NpcLine(new TextObject("{=gNHh9bvb}I am sorry that you did not manage to make a profit. But you are keeping your end of the bargain, and that is admirable.", null), null, null).Consequence(delegate
				{
					Campaign.Current.ConversationManager.ConversationEndOneShot += this.PlayerPaidAgreedDenarsQuestSuccess;
				}).CloseDialog().PlayerOption(text2, null).ClickableCondition(new ConversationSentence.OnClickableConditionDelegate(this.PlayerFailWithGoldClickableCondition)).Condition(delegate
				{
					if (this._gatheredDenars > 0)
					{
						playerFailOptionWithGold.SetTextVariable("GATHERED_DENARS", this._gatheredDenars);
						Campaign.Current.ConversationManager.GetCurrentDialogLine().SetTextVariable("PLAYER_FAIL_OPTION", playerFailOptionWithGold);
					}
					else
					{
						Campaign.Current.ConversationManager.GetCurrentDialogLine().SetTextVariable("PLAYER_FAIL_OPTION", playerFailOptionNoGold);
					}
					return true;
				}).NpcLine(textObject6, null, null).Consequence(delegate
				{
					Campaign.Current.ConversationManager.ConversationEndOneShot += this.QuestFailedPlayerBrokeTheAgreement;
				}).CloseDialog().PlayerOption(textObject7, null).NpcLine(new TextObject("{=RxjuaDum}I am glad of that. Don't make me wait too long. Some men say they will pay a debt, and you never see them again.[if:convo_mocking_teasing][ib:confident2]", null), null, null).CloseDialog().EndPlayerOptions().PlayerOption(textObject4, null).Condition(() => this.QuestCanBeFinalized && !this._productsUndersold).NpcLine(new TextObject("{=9jFqXvHy}Excellent! I knew you were an honest soul. Trust is a fine thing, isn't it? Perhaps we can do more business in the future.[if:convo_innocent_smile][ib:confident]", null), null, null).Consequence(new ConversationSentence.OnConsequenceDelegate(this.QuestSuccessPlayerSoldTheProducts)).CloseDialog().EndPlayerOptions().EndNpcOptions();
			}

			// Token: 0x06004F09 RID: 20233 RVA: 0x0016925C File Offset: 0x0016745C
			private void QuestSuccessPlayerSoldTheProducts()
			{
				base.AddLog(this.QuestSuccessLogText, false);
				GainRenownAction.Apply(Hero.MainHero, 1f, false);
				this.RelationshipChangeWithQuestGiver = 10;
				GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, base.QuestGiver, this._targetDenarsToAchieve, false);
				base.CompleteQuestWithSuccess();
			}

			// Token: 0x06004F0A RID: 20234 RVA: 0x001692AC File Offset: 0x001674AC
			private void QuestFailedPlayerBrokeTheAgreement()
			{
				base.AddLog(this.QuestFailedPlayerBrokeTheAgreementLogText, false);
				ChangeCrimeRatingAction.Apply(base.QuestGiver.MapFaction, 5f, true);
				base.QuestGiver.AddPower(-5f);
				GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, base.QuestGiver, this._gatheredDenars, false);
				this.RelationshipChangeWithQuestGiver = -10 - this.RemainingDenars / 10;
				base.CompleteQuestWithFail(null);
			}

			// Token: 0x06004F0B RID: 20235 RVA: 0x00169320 File Offset: 0x00167520
			private void PlayerPaidAgreedDenarsQuestSuccess()
			{
				GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, base.QuestGiver, this._targetDenarsToAchieve, false);
				this.RelationshipChangeWithQuestGiver = 10;
				GainRenownAction.Apply(Hero.MainHero, 1f, false);
				base.AddLog(this.QuestSuccessWithPayingGatheredDenarsLogText, false);
				base.CompleteQuestWithSuccess();
			}

			// Token: 0x06004F0C RID: 20236 RVA: 0x00169370 File Offset: 0x00167570
			private bool PlayerPayAgreedDenarsClickableCondition(out TextObject explanation)
			{
				explanation = TextObject.Empty;
				if (Hero.MainHero.Gold < this._targetDenarsToAchieve)
				{
					explanation = new TextObject("{=d0kbtGYn}You don't have enough gold.", null);
					return false;
				}
				MBTextManager.SetTextVariable("REMAINING_DENARS", this.RemainingDenars);
				return true;
			}

			// Token: 0x06004F0D RID: 20237 RVA: 0x001693AB File Offset: 0x001675AB
			private bool PlayerFailWithGoldClickableCondition(out TextObject explanation)
			{
				explanation = TextObject.Empty;
				if (this._gatheredDenars > 0 && Hero.MainHero.Gold < this._gatheredDenars)
				{
					explanation = new TextObject("{=d0kbtGYn}You don't have enough gold.", null);
					return false;
				}
				return true;
			}

			// Token: 0x06004F0E RID: 20238 RVA: 0x001693E0 File Offset: 0x001675E0
			private void QuestAcceptedConsequences()
			{
				base.StartQuest();
				base.AddTrackedObject(base.QuestGiver.CurrentSettlement);
				MobileParty.MainParty.ItemRoster.AddToCounts(this._selectedItemObject, this._selectedItemObjectCount);
				TextObject textObject = new TextObject("{=jKHkGzUn}As agreed, {SELECTED_ITEM_COUNT} {?IS_PLURAL}{.%}{PLURAL(SELECTED_ITEM)}{.%} have been{?}{.%}{SELECTED_ITEM}{.%} has been{\\?} added to your inventory.", null);
				textObject.SetTextVariable("SELECTED_ITEM", this._selectedItemObject.Name);
				textObject.SetTextVariable("SELECTED_ITEM_COUNT", this._selectedItemObjectCount);
				textObject.SetTextVariable("IS_PLURAL", (this._selectedItemObjectCount > 1) ? 1 : 0);
				MBInformationManager.AddQuickInformation(textObject, 0, null, "");
				base.AddLog(this.QuestStartedLogText1, false);
				base.AddLog(this.QuestStartedLogText2, false);
				base.AddLog(this.QuestStartedLogText3, false);
				TextObject textObject2 = new TextObject("{=GaXEmoFy}Sold {.%}{SELECTED_ITEM}{.%} amount:", null);
				textObject2.SetTextVariable("SELECTED_ITEM", this._selectedItemObject.Name);
				TextObject textObject3 = new TextObject("{=pwnqk0Nj}Gathered denars from {.%}{SELECTED_ITEM}{.%}", null);
				textObject3.SetTextVariable("SELECTED_ITEM", this._selectedItemObject.Name);
				this._soldItemAmountLog = base.AddDiscreteLog(TextObject.Empty, textObject2, this._soldCount, this._selectedItemObjectCount, null, false);
				this._gatheredDenarsLog = base.AddDiscreteLog(TextObject.Empty, textObject3, this._gatheredDenars, this._targetDenarsToAchieve, null, false);
			}

			// Token: 0x06004F0F RID: 20239 RVA: 0x0016952C File Offset: 0x0016772C
			private void QuestFinishedPlayerBoughtTheGoods()
			{
				base.AddLog(this.QuestSuccessPlayerBoughtItemsLogText, false);
				MobileParty.MainParty.ItemRoster.AddToCounts(this._selectedItemObject, this._selectedItemObjectCount);
				GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, base.QuestGiver, this._targetDenarsToAchieve, false);
				GainRenownAction.Apply(Hero.MainHero, 1f, false);
				this.RelationshipChangeWithQuestGiver = 1;
				base.CompleteQuestWithSuccess();
			}

			// Token: 0x06004F10 RID: 20240 RVA: 0x00169597 File Offset: 0x00167797
			private bool PlayerBuyClickableOptionCondition(out TextObject explanation)
			{
				explanation = TextObject.Empty;
				if (Hero.MainHero.Gold < this._targetDenarsToAchieve)
				{
					explanation = new TextObject("{=d0kbtGYn}You don't have enough gold.", null);
					return false;
				}
				return true;
			}

			// Token: 0x06004F11 RID: 20241 RVA: 0x001695C2 File Offset: 0x001677C2
			protected override void OnTimedOut()
			{
				base.AddLog(this.QuestFailedWithTimeOutLogText, false);
				this.RelationshipChangeWithQuestGiver = -10;
				ChangeCrimeRatingAction.Apply(base.QuestGiver.MapFaction, 5f, true);
			}

			// Token: 0x06004F12 RID: 20242 RVA: 0x001695F0 File Offset: 0x001677F0
			protected override void RegisterEvents()
			{
				CampaignEvents.WarDeclared.AddNonSerializedListener(this, new Action<IFaction, IFaction, DeclareWarAction.DeclareWarDetail>(this.OnWarDeclared));
				CampaignEvents.OnClanChangedKingdomEvent.AddNonSerializedListener(this, new Action<Clan, Kingdom, Kingdom, ChangeKingdomAction.ChangeKingdomActionDetail, bool>(this.OnClanChangedKingdom));
				CampaignEvents.VillageBeingRaided.AddNonSerializedListener(this, new Action<Village>(this.OnVillageRaided));
				CampaignEvents.PlayerInventoryExchangeEvent.AddNonSerializedListener(this, new Action<List<ValueTuple<ItemRosterElement, int>>, List<ValueTuple<ItemRosterElement, int>>, bool>(this.OnPlayerInventoryExchange));
				CampaignEvents.MapEventStarted.AddNonSerializedListener(this, new Action<MapEvent, PartyBase, PartyBase>(this.OnMapEventStarted));
			}

			// Token: 0x06004F13 RID: 20243 RVA: 0x00169670 File Offset: 0x00167870
			private void OnMapEventStarted(MapEvent mapEvent, PartyBase attackerParty, PartyBase defenderParty)
			{
				if (QuestHelper.CheckMinorMajorCoercion(this, mapEvent, attackerParty))
				{
					QuestHelper.ApplyGenericMinorMajorCoercionConsequences(this, mapEvent);
				}
			}

			// Token: 0x06004F14 RID: 20244 RVA: 0x00169683 File Offset: 0x00167883
			protected override void HourlyTick()
			{
				if (base.IsOngoing && !this._underSoldLogAdded && this.CheckIfPlayerLostItem())
				{
					base.AddLog(this.QuestReadyToBeFinishedUnderSoldLogText, false);
					this._daysPassed++;
					this._underSoldLogAdded = true;
				}
			}

			// Token: 0x06004F15 RID: 20245 RVA: 0x001696C0 File Offset: 0x001678C0
			private bool CheckIfPlayerLostItem()
			{
				return this._soldCount + MobileParty.MainParty.ItemRoster.GetItemNumber(this._selectedItemObject) < this._selectedItemObjectCount;
			}

			// Token: 0x06004F16 RID: 20246 RVA: 0x001696E8 File Offset: 0x001678E8
			private void OnPlayerInventoryExchange(List<ValueTuple<ItemRosterElement, int>> purchasedItems, List<ValueTuple<ItemRosterElement, int>> soldItems, bool isTrading)
			{
				if (isTrading && this.ItemCountLeftToSell > 0)
				{
					foreach (ValueTuple<ItemRosterElement, int> valueTuple in soldItems)
					{
						ItemRosterElement item = valueTuple.Item1;
						if (item.EquipmentElement.Item == this._selectedItemObject)
						{
							int soldCount = this._soldCount;
							item = valueTuple.Item1;
							this._soldCount = soldCount + item.Amount;
							this._gatheredDenars += valueTuple.Item2;
						}
					}
					if (this.ItemCountLeftToSell <= 0)
					{
						base.AddLog(this.QuestReadyToBeFinishedLogText, false);
					}
					this._productsUndersold = (this._gatheredDenars < this._targetDenarsToAchieve);
					this._soldItemAmountLog.UpdateCurrentProgress(this._soldCount);
					this._gatheredDenarsLog.UpdateCurrentProgress(this._gatheredDenars);
				}
			}

			// Token: 0x06004F17 RID: 20247 RVA: 0x001697DC File Offset: 0x001679DC
			private void OnVillageRaided(Village village)
			{
				if (village == base.QuestGiver.CurrentSettlement.Village)
				{
					base.AddLog(this.QuestGiverVillageRaided, false);
					base.CompleteQuestWithCancel(null);
				}
			}

			// Token: 0x06004F18 RID: 20248 RVA: 0x00169806 File Offset: 0x00167A06
			private void OnClanChangedKingdom(Clan clan, Kingdom oldKingdom, Kingdom newKingdom, ChangeKingdomAction.ChangeKingdomActionDetail detail, bool showNotification = true)
			{
				if (base.QuestGiver.CurrentSettlement.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
				{
					base.CompleteQuestWithCancel(this.QuestCanceledWarDeclaredLog);
				}
			}

			// Token: 0x06004F19 RID: 20249 RVA: 0x00169835 File Offset: 0x00167A35
			private void OnWarDeclared(IFaction faction1, IFaction faction2, DeclareWarAction.DeclareWarDetail detail)
			{
				QuestHelper.CheckWarDeclarationAndFailOrCancelTheQuest(this, faction1, faction2, detail, this.PlayerDeclaredWarQuestLogText, this.QuestCanceledWarDeclaredLog, false);
			}

			// Token: 0x06004F1A RID: 20250 RVA: 0x0016984D File Offset: 0x00167A4D
			protected override void OnFinalize()
			{
			}

			// Token: 0x06004F1B RID: 20251 RVA: 0x0016984F File Offset: 0x00167A4F
			protected override void InitializeQuestOnGameLoad()
			{
				this._targetDenarsToAchieve = (int)((float)(this._selectedItemObject.Value * this._selectedItemObjectCount) * 0.55f);
				this._productsUndersold = (this._gatheredDenars < this._targetDenarsToAchieve);
				this.SetDialogs();
			}

			// Token: 0x04001A37 RID: 6711
			[SaveableField(10)]
			private ItemObject _selectedItemObject;

			// Token: 0x04001A38 RID: 6712
			[SaveableField(20)]
			private int _selectedItemObjectCount;

			// Token: 0x04001A39 RID: 6713
			[SaveableField(30)]
			private int _soldCount;

			// Token: 0x04001A3A RID: 6714
			[SaveableField(40)]
			private int _gatheredDenars;

			// Token: 0x04001A3B RID: 6715
			private bool _productsUndersold = true;

			// Token: 0x04001A3C RID: 6716
			[SaveableField(60)]
			private int _daysPassed;

			// Token: 0x04001A3D RID: 6717
			[SaveableField(70)]
			private bool _underSoldLogAdded;

			// Token: 0x04001A3E RID: 6718
			private int _targetDenarsToAchieve;

			// Token: 0x04001A3F RID: 6719
			[SaveableField(80)]
			private JournalLog _soldItemAmountLog;

			// Token: 0x04001A40 RID: 6720
			[SaveableField(90)]
			private JournalLog _gatheredDenarsLog;
		}

		// Token: 0x02000643 RID: 1603
		public class LandLordTheArtOfTheTradeIssueBehaviorTypeDefiner : SaveableTypeDefiner
		{
			// Token: 0x06004F1C RID: 20252 RVA: 0x0016988B File Offset: 0x00167A8B
			public LandLordTheArtOfTheTradeIssueBehaviorTypeDefiner() : base(249000)
			{
			}

			// Token: 0x06004F1D RID: 20253 RVA: 0x00169898 File Offset: 0x00167A98
			protected override void DefineClassTypes()
			{
				base.AddClassDefinition(typeof(LandLordTheArtOfTheTradeIssueBehavior.LandLordTheArtOfTheTradeIssue), 1, null);
				base.AddClassDefinition(typeof(LandLordTheArtOfTheTradeIssueBehavior.LandLordTheArtOfTheTradeIssueQuest), 2, null);
			}
		}
	}
}
